﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WEBDT.Base;
using WEBDT.ViewModel;
namespace WEBDT.Areas.Admin.Controllers
{
    public class NhomSPController : BaseController<NhomSP>
    {
        //
        // GET: /Admin/User/

        public ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        public override ActionResult insert()
        {
            var model = new NhomSPModel
            {
                tontai = false,
            };
            return View(model);
        }

        [HttpPost]
        public override ActionResult insert(FormCollection fr)
        {
            var ht = new NhomSPModel
            {
                TenNhom = fr.Get("tennhom"),
            };
            var model = new NhomSP
            {
                TenNhom = ht.TenNhom,
            };
            repository.Insert<NhomSP>(model);
            return RedirectToAction("getall");

        }

        [HttpGet]
        public override ActionResult update(int id)
        {
            var ht = repository.SelectByID<NhomSP>(id);
            var model = new NhomSPModel
            {
                MaNhom = ht.MaNhom,
                TenNhom = ht.TenNhom,

            };
            return View(model);
        }

        [HttpPost]
        public override ActionResult update(FormCollection fr)
        {
            var ht = new NhomSPModel
            {
                MaNhom = Convert.ToInt32(fr.Get("manhom")),
                TenNhom = fr.Get("tennhom"),
            };
            var model = repository.SelectByID<NhomSP>(ht.MaNhom);
            model.TenNhom = ht.TenNhom;
            repository.commitchanges();
            return RedirectToAction("getall");
        }
    }
}
